package com.axend.sofa.ui.activity

import android.os.Bundle
import android.view.View
import com.alibaba.android.arouter.facade.annotation.Route
import com.axend.lib_base.ext.click
import com.axend.lib_base.help.ble.BleMsgProcessor
import com.axend.lib_base.help.ble.enums.BleCommandTag
import com.axend.lib_base.view.dialog.CustomCalibrationDialog
import com.axend.sofa.base.BaseBleVVDActivity
import com.axend.lib_service.ARouterPath
import com.axend.sofa.BR
import com.axend.sofa.R
import com.axend.sofa.databinding.ActivityCalibrationBinding
import com.axend.sofa.viewmodel.CalibrationViewModel

/**
 * @description校准页面
 * @author admins
 * @time 2025/3/5 11:59
 */
@Route(path = ARouterPath.ACTIVITY_CALIBRATION)
class CalibrationActivity : BaseBleVVDActivity<CalibrationViewModel, ActivityCalibrationBinding>() {
    private val dialog: CustomCalibrationDialog by lazy {
        CustomCalibrationDialog(
            this,
            { dialog.dismiss() },
        ) {
            /*停止学习*/
            mViewModel.writeBleMsg(
                BleMsgProcessor.encodeMsg(
                    BleCommandTag.SET_STUDY_END.getMarkFixCommand(),
                    BleCommandTag.SET_STUDY_END
                )
            )
        }
    }

    override fun init(savedInstanceState: Bundle?) {
        super.init(savedInstanceState)
        mBinding.setVariable(BR.viewmodel, mViewModel)
        mBinding.executePendingBindings()

        mBinding.btStart.click {
            /*开始学习*/
            mViewModel.writeBleMsg(
                BleMsgProcessor.encodeMsg(
                    BleCommandTag.GET_VERSION.getMarkFixCommand(),
                    BleCommandTag.SET_STUDY_START
                )
            )
        }

        mViewModel.dialogModel.observe(this) {
            dialog.setModel(it)
        }
    }
}